<style type="text/css">
.validator {
    background: -moz-linear-gradient(center top , #2D2D2D 0%, #0E0E0E 100%) repeat scroll 0 0 transparent;
    border-radius: 5px 5px 5px 5px;
    color: #FFFFFF;
    font-size: 85%;
    height: 18px;
    line-height: 18px;
    margin-left: -2px;
    opacity: 0.8;
    padding: 3px 10px;
    vertical-align: middle;
	position:absolute;
}
.validator .arrow {
    border-color: #0E0E0E transparent -moz-use-text-color;
    border-left: 0 solid transparent;
    border-right: 6px solid transparent;
    border-style: solid solid none;
    border-width: 6px 6px 0 0;
    bottom: -6px;
    display: block;
    height: 0;
    left: 10px;
    position: absolute;
    width: 0;
}
input.invalid, textarea.invalid {
    box-shadow: 0 0 3px red;
}
.no-boxshadow input.invalid, .no-boxshadow textarea.invalid {
    background-color: #FFF5F7;
    border: 1px solid red;
}
</style>
<?php echo $this->Html->script(array('jquery.form')); ?>
<?php //$this->Html->scriptStart(array('inline' => false)); ?>
<script type="text/javascript">
	// wait for the DOM to be loaded 
	$(document).ready(function() { 
		var options = { 
			url: $('#VenueAddForm').attr('action'),
			clearForm :true,
			success: function() { 
				$('.invalid').removeClass('invalid');
				alert('Thanks for your comment!'); 
			},
			error: function(data,type,status) { 
				$('.invalid').removeClass('invalid');
				response=$.parseJSON(data.responseText);
				$.each(response.errors, function(key, val) {
					if (val instanceof Object) {
						$.each(val, function(key2, val2) {
							if (val2 instanceof Object) {
								$.each(val2, function(key3, val3) {
									if(typeof key2 != 'undefined' && typeof key3 != 'undefined' && typeof val3 != 'undefined') {
										var field_id = ucwords(key) + key2 + ucwords(key3);
										var field_error = val3;
							if ($('#validator_'+field_id).length == 0 && typeof field_id != 'undefined' && typeof field_error != 'undefined') {
							$('#'+field_id).parent().append('<div id="validator_' + field_id + '" class="validator"><span class="arrow"></span><p>'+field_error+'</p></div>');
							
							}
										if($("#"+field_id).offset()!=null) {
										$('#validator_' + field_id).css({top: $("#"+field_id).offset().top - 30, left: $("#"+field_id).offset().left}).show().delay(2000).fadeOut('slow');
										
										$('#'+field_id).addClass('invalid');
										}
									}
								});
							} else {
								if(typeof key2 != 'undefined' && typeof val2 != 'undefined') {
									var field_id = ucwords(key) + ucwords(key2);
									var field_error = val2;
																if ($('#validator_'+field_id).length == 0){
							$('#'+field_id).parent().append('<div id="validator_' + field_id + '" class="validator"><span class="arrow"></span><p>'+field_error+'</p></div>');
							}
									$('#validator_' + field_id).css({top: $("#"+field_id).offset().top - 30, left: $("#"+field_id).offset().left}).show().delay(2000).fadeOut('slow');
									$('#'+field_id).addClass('invalid');
								}
							}
						});
					} else {
						if(typeof key != 'undefined' && typeof val != 'undefined') {
							var field_id = ucwords(key);
							var field_error = val;
							if ($('#validator_'+field_id).length == 0){
							$('#'+field_id).parent().append('<div id="validator_' + field_id + '" class="validator"><span class="arrow"></span><p>'+field_error+'</p></div>');
							}
							 $('#validator_' + field_id).css({top: $("#"+field_id).offset().top - 30, left: $("#"+field_id).offset().left}).show().delay(2000).fadeOut('slow');
							 $('#'+field_id).addClass('invalid');
						}	
					}
				});
			}
		}; 
		//bind 'myForm' and provide a simple callback function 
		$('#VenueAddForm').ajaxForm(options); 
	}); 

    function parse_fields(key1, val1) {
		
    }

	function actualFunction(field_name, field_error) {
		console.log(field_name);
		console.log(field_error);
	}
	
	function ucwords(string) {
		return string.charAt(0).toUpperCase() + string.slice(1);
	}

</script>
<?php //$this->Html->scriptEnd(); ?>
<div class="venues form">
<?php echo $this->Form->create('Venue');?>
	<fieldset>
		<legend><?php __('Add Venue'); ?></legend>
	<?php
		echo $this->Form->input('marker_id');
		echo $this->Form->input('user_id');
		echo $this->Form->input('type');
		echo $this->Form->input('VenueDetail.name');
		echo $this->Form->input('VenueDetail.description');
		echo $this->Form->input('VenueDetail.address1');
		echo $this->Form->input('VenueDetail.address2');
		echo $this->Form->input('VenueDetail.postal_code');
		echo $this->Form->input('VenueDetail.country_id');
		echo $this->Form->input('VenueDetail.phone');
		echo $this->Form->input('VenueDetail.web');
		/*echo $this->Form->input('VenueDetail.0.name');
		echo $this->Form->input('VenueDetail.0.description');
		echo $this->Form->input('VenueDetail.0.address1');
		echo $this->Form->input('VenueDetail.0.address2');
		echo $this->Form->input('VenueDetail.0.postal_code');
		echo $this->Form->input('VenueDetail.0.country_id');
		echo $this->Form->input('VenueDetail.0.phone');
		echo $this->Form->input('VenueDetail.0.web');*/
		echo $this->Form->input('is_active');
		echo $this->Form->input('Guide');
	?>
	</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
</div>
<div class="actions">
	<h3><?php __('Actions'); ?></h3>
	<ul>
		<li><?php echo $this->Html->link(__('List Venues', true), array('action' => 'index'));?></li>
		<li><?php echo $this->Html->link(__('List Markers', true), array('controller' => 'markers', 'action' => 'index')); ?> </li>
		<li><?php echo $this->Html->link(__('New Marker', true), array('controller' => 'markers', 'action' => 'add')); ?> </li>
		<li><?php echo $this->Html->link(__('List Users', true), array('controller' => 'users', 'action' => 'index')); ?> </li>
		<li><?php echo $this->Html->link(__('New User', true), array('controller' => 'users', 'action' => 'add')); ?> </li>
		<li><?php echo $this->Html->link(__('List Venue Details', true), array('controller' => 'venue_details', 'action' => 'index')); ?> </li>
		<li><?php echo $this->Html->link(__('New Venue Detail', true), array('controller' => 'venue_details', 'action' => 'add')); ?> </li>
		<li><?php echo $this->Html->link(__('List Venue Tips', true), array('controller' => 'venue_tips', 'action' => 'index')); ?> </li>
		<li><?php echo $this->Html->link(__('New Venue Tip', true), array('controller' => 'venue_tips', 'action' => 'add')); ?> </li>
		<li><?php echo $this->Html->link(__('List Guides', true), array('controller' => 'guides', 'action' => 'index')); ?> </li>
		<li><?php echo $this->Html->link(__('New Guide', true), array('controller' => 'guides', 'action' => 'add')); ?> </li>
	</ul>
</div>